<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>进度条</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .mb {
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            background-color: rgba(0, 0, 0, .5);
            display: none;
        }

        .content {
            width: 540px;
            box-sizing: border-box;
            background-color: #fff;
            display: inline-block;
            padding: 20px 20px;
            position: absolute;
            top: 10%;
            left: 50%;
            margin-left: -270px;
        }

        .content>p {
            width: 0;
            height: 100px;
            background: repeating-linear-gradient(135deg, green 0, green 10px, #fff 0, #fff 20px);
        }

        .content>input {
            position: absolute;
            top: 0;
            right: 0;
        }
    </style>
</head>

<body>
    <h1>title</h1>
    <input type="button" value="click me" id="clickBtn">
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Officia minus praesentium qui deleniti est vel fugit
        facilis aliquid, beatae quidem iusto impedit sint, fuga cupiditate fugiat perferendis atque tempora hic?</p>
    <div class="mb">
        <div class="content">
            <p></p>
            <i>0%</i>
            <input type="button" value="close" id="closeBtn">
        </div>
    </div>

    <script>
        let number = document.querySelector("i");   // 数字
        let progressBar = document.querySelector(".content>p"); // 进度条
        let clickBtn = document.getElementById("clickBtn");
        let closeBtn = document.getElementById("closeBtn"); // 关闭按钮
        let mb = document.querySelector(".mb"); // 蒙版

        let i = 0, timer = null;

        // 开始按钮
        clickBtn.onclick = function () {
            mb.style.display = 'block';
            i = 0;
            timer = setInterval(function () {
                if (i <= 100) {
                    number.innerText = i + '%'; // 数字
                    progressBar.style.width = 5 * i + 'px';// 进度条
                    i++;
                } else {
                    clearInterval(timer);
                }
            }, 100);
        }
        // 关闭按钮
        closeBtn.onclick = function () {
            mb.style.display = 'none';
            clearInterval(timer);
            // 样式清空
            number.innerText = '0%'; // 数字
            progressBar.style.width = '0px';// 进度条
        }

      

    </script>
</body>

</html>